package com.lianzt.util;


import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

import com.lianzt.commondata.AbstractCommonData;
import com.lianzt.commondata.DataConvertFactory;



public class SSLConnection {

	public static AbstractCommonData sendHttpPost(String url, BasicNameValuePair xml)
			throws Exception {
		AbstractCommonData back_acd = null;
		HttpClient httpclient = new DefaultHttpClient();
		HttpPost httppost = new HttpPost(url);
		List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
		nameValuePairs.add(xml);
		HttpEntity entity=new UrlEncodedFormEntity(nameValuePairs,HTTP.UTF_8);		
		httppost.setEntity(entity);
		HttpResponse httpResponse = httpclient.execute(httppost);
		
		if (httpResponse.getStatusLine().getStatusCode() == 200) {
			String strResult = EntityUtils.toString(httpResponse.getEntity());			
			back_acd = DataConvertFactory.getInstance(strResult);
		} else {
			httpResponse.getStatusLine().toString();
		}
		return back_acd;
	}
}
